package com.ithiema.controller;

import com.ithiema.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;


@Controller
@RequestMapping("/user")
@SessionAttributes(names = "username")
public class UserController {

    //不通过Servlet进行登录验证
    @RequestMapping("/login")
    public String login(User user, Model model){
        if ("zhangsan".equals(user.getUsername()) && "123".equals(user.getPassword())){
            model.addAttribute("username",user.getUsername());
            return "success";
        }
        return "redirect:/login.jsp";
    }


    //通过HttpSession进行操作
//    @RequestMapping("/login")
//    public String login(User user, HttpSession session){
//        if ("zhangsan".equals(user.getUsername()) && "123".equals(user.getPassword())){
//            session.setAttribute("username",user.getUsername());
//            return "success";
//        }
//        return "redirect:/login.jsp";
//    }

}
